import type { Module } from 'vuex'
import type { ILoginState } from './types'
import type { IRootState } from '../types'

//import router from '@/router'

import { accountLoginRequest } from '@/services/login/login'

const login: Module<ILoginState, IRootState> = {
  namespaced: true,
  state() {
    return {
      token: '',
      userInfo: {},
      userMenus: {},
      permissions: []
    }
  },
  getters: {},
  mutations: {},
  actions: {
    async accountLoginAction(
      /* 没有接口.. */
      { commit, dispatch },
      account: { name: string; password: string }
    ) {
      // 1.用户登录
      const loginResult = await accountLoginRequest(account)
      const { id, token } = loginResult
      console.log(id, token)
    }
  }
}

export default login
